module.exports = {
    state: {
        parking: {}
    },
    mutations: {
        parking (state, data) {
            state.parking = {
                list: data
            }
        }
    },
    actions: {
        getParking ({commit, state}, resolve) {
            uid = $store.getters.userID
            $store.api.call('parking_list', {
                message: '获取停车记录失败',
                form: {id: uid}
            }, ({data}) => {
                commit('parking', data)
                if(resolve && resolve.call) {
                    resolve(data)
                }
            })
        },
        bookParking ({commit, state}, {day, car, resolve}) {
            uid = $store.getters.userID
            $store.api.call('parking_book', {
                message: '预定车位失败',
                params: {day},
                form: {uid, car}
            }, ({data}) => {
                commit('parking', data)
                if(resolve && resolve.call) {
                    resolve(data)
                }
            })
        },
        cancelParking ({commit, state}, {day, resolve}) {
            uid = $store.getters.userID
            $store.api.call('parking_cancel', {
                message: '取消预定车位失败',
                params: {day}
            }, ({data}) => {
                commit('parking', data)
                if(resolve && resolve.call) {
                    resolve(data)
                }
            })
        }
    },
    getters: {
        parkingList (state) {
            return state.parking
        }
    }
}